import { createActions, handleActions } from 'redux-actions'

export const { setStudents, loading, fetchStudents } = createActions({
    SET_STUDENTS: ({ datas, total }) => ({ datas, total }),
    LOADING: payload => payload,
    FETCH_STUDENTS: null
})

// @ts-ignore
export const reducer = handleActions({
    [setStudents.toString()]: (state, { payload: { datas, total } }) => ({ ...state, datas, total }),
    [loading.toString()]: (state, { payload }) => ({ ...state, isLoading: payload })
}, {
    datas: [],
    total: 0,
    isLoading: false
})
